
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>

#define LIMIT_TEMP 55
#define DEFINE_PIN 15

int main(int argn, char **argv)
{
    int root = DEFINE_PIN;
    FILE *temperatureFile;
    int T;
    int limit = LIMIT_TEMP * 1000;

    printf("%d %s", argn, argv[1]);
    if (argn >= 2)
    {
        sscanf(argv[1], "%d", &root);
    }
    printf("working pin:%d\n",root);

    wiringPiSetup();
 pinMode (root, OUTPUT) ;
    for (;;)
    {
        temperatureFile = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
        if (temperatureFile == NULL) //print some message
        {
            T = 60000;
        }
        else
        {
            fscanf(temperatureFile, "%d", &T); // read temp
            fclose(temperatureFile);
        }
        // printf("%d\n",T);
        if (T > limit)
        {
            // puts("hot");
            digitalWrite(root, LOW);
        }
        else
        {
            // puts("cool");
            digitalWrite(root, HIGH);
        }
        delay(2000);
    }
}